package cuiyt.juc.volatiletest;

/**
 * @author cyt
 * @create 2020-05-03 23:58
 */
public class demo {
    private volatile static int num = 10;

    public   static void increase() {
        num++;
    }

    public static void main(String[] args) {
        for (int i = 0; i < 20; i++) {
            new Thread(() -> {
                for (int j = 0; j < 1000; j++) {
                    increase();
                }
            }, String.valueOf(i)).start();
        }

        while (Thread.activeCount() > 2) {
            Thread.yield();
        }
        System.out.println(Thread.currentThread().getName() + num);
    }
}
